//index.js
//获取应用实例
const wx = require('../../libs/wx.js');
const {getSales} = require('../../apis');
const config = require('../../config');
const Page = require('../../libs/BasePage');
const app = getApp();
Page({
    data: {
        sales: [],
        company: {}
    },

    onShow: function () {
        const animation = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease',
        });

        const func = () => {
            animation.translateY(-5).scale(1.5).step();
            this.setData({
                animationData: animation.export()
            })

            animation.translateY(0).scale(1).step();
        }

        func();

        setInterval(func, 1000)
    },

    onShareAppMessage() {
      return {
        title: config.name + ' - 特惠' ,
        path: '/pages/sales/sales',
      }
    },

    goToMap() {
        wx.openLocation({
            longitude: this.data.company.location[0],
            latitude: this.data.company.location[1],
            name: config.name,
            address: this.data.company.address
        });
    },


    onLoad () {
        getSales().then((res) => {
            const sales = res.data.data;

            this.setData({sales});
        });

        app.getCompanyDetail().then((res) => {

            const {clerks, company, sales} = res;

            this.setData({company});
        })
    },

    previewSale(e){
        wx.previewImage({
            current: e.currentTarget.dataset.url,
            urls: e.currentTarget.dataset.urls
        })
    },

    onCallClick(){
        wx.makePhoneCall({
            phoneNumber: this.data.company.phoneNum||''
        })
    },

    previewImage(e){
        wx.previewImage({
            current: e.currentTarget.dataset.url,
            urls: e.currentTarget.dataset.urls
        })
    },

});
